/**
 * Copyright &copy; 2013-2015 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.modules.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.modules.sys.entity.UserDictType;
import cn.net.ecode.modules.sys.service.UserDictTypeService;

/**
 * 用户字典类型管理Controller
 * @author ThinkGem
 * @version 2015-07-27
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/userDictType")
public class UserDictTypeController extends BaseController {

	@Autowired
	private UserDictTypeService userDictTypeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public UserDictType get(String dictTypeCode, boolean isNewRecord) {
		return userDictTypeService.get(dictTypeCode, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sys:userDictType:view")
	@RequestMapping(value = {"list", ""})
	public String list(UserDictType userDictType, Model model) {
		return "modules/sys/userDictTypeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("sys:userDictType:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<UserDictType> listData(UserDictType userDictType, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<UserDictType> page = userDictTypeService.findPage(new Page<UserDictType>(request, response), userDictType); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sys:userDictType:view")
	@RequestMapping(value = "form")
	public String form(UserDictType userDictType, Model model) {
		model.addAttribute("userDictType", userDictType);
		return "modules/sys/userDictTypeForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("sys:userDictType:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(UserDictType userDictType) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, userDictType)){
			return renderResult(Global.FALSE, message);
		}
		userDictTypeService.save(userDictType);
		return renderResult(Global.TRUE, "保存用户字典类型成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("sys:userDictType:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(UserDictType userDictType) {
		userDictTypeService.delete(userDictType);
		return renderResult(Global.TRUE, "删除用户字典类型成功！");
	}

}